home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xarchie-2.0.9 / settings.c < prev    next >
C/C++ Source or Header  |  1995-06-18  |  22KB  |  787 lines

  1. /*
  2.  * settings.c : Set program parameters on a popup panel
  3.  *
  4.  * George Ferguson, ferguson@cs.rochester.edu, 22 Oct 1991.
  5.  * Version 2.0: 23 Apr 1993.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <X11/Intrinsic.h>
  10. #include <X11/Shell.h>
  11. #include <X11/StringDefs.h>
  12. #include <X11/Xaw/Form.h>
  13. #include <X11/Xaw/MenuButton.h>
  14. #include <X11/Xaw/Label.h>
  15. #include <X11/Xaw/AsciiText.h>
  16. #include <X11/Xaw/Cardinals.h>
  17. #include "xarchie.h"
  18. #include "types.h"
  19. #include "appres.h"
  20. #include "m-defs.h"
  21. #include "rdgram.h"
  22. #include "alert.h"
  23. #include "status.h"
  24. #include "popups.h"
  25. #include "xutil.h"
  26. #include "stringdefs.h"
  27. #include "weight.h"
  28. #include "tilde.h"
  29. extern void resortBrowser();        /* browser.c */
  30.  
  31. /*
  32.  * Functions declared in this file
  33.  */
  34. void initSettings(),reinitSettings();
  35. void setSettingsShellState();
  36. void updateSettingsHost(),updateSettingsSearchType();
  37. void updateSettingsSortType(),updateSettingsNiceLevel();
  38. void updateSettingsAutoScroll();
  39. void updateSettingsFtpType(),updateSettingsFtpPrompt();
  40. void updateSettingsFtpTrace(),updateSettingsFtpStrip();
  41. void setSettingsChangedFlag();
  42.  
  43. static void initSettingsWidgets();
  44. static void addTextEventHandler(),textEventProc();
  45. static void popupSettingsAction();
  46. static void applySettingsAction(),defaultSettingsAction(),doneSettingsAction();
  47. static void setHostAction(),setSearchTypeAction();
  48. static void setSortTypeAction(),setNiceLevelAction();
  49. static void setHostNowAction(),setSearchTypeNowAction();
  50. static void setSortTypeNowAction(),setNiceLevelNowAction();
  51. static int settingsConfirm();
  52. static void settingsConfirmCallback();
  53.  
  54. /*
  55.  * Data declared in this file
  56.  */
  57. static Widget settingsShell;
  58. static Widget setApplyButton;
  59. static Widget setHostText;
  60. static Widget setSearchLabel,setSortLabel;
  61. static Widget setNiceText,setMaxHitsText;
  62. static Widget setTimeoutText,setRetriesText;
  63. static Widget setAutoScrollLabel;
  64. static Widget ftpLocalDirText,ftpTypeLabel;
  65. static Widget ftpPromptLabel,ftpTraceLabel,ftpStripLabel;
  66. static Widget ftpMailAddressText;
  67. static Widget setHostWeightsLabel,setHostWeightsText;
  68.  
  69. static char *defArchieHost;
  70. static SearchType currentSearchType,defSearchType;
  71. static SortType currentSortType,defSortType;
  72. static int defMaxHits,defTimeout,defRetries,defNiceLevel;
  73. static Boolean currentAutoScroll,defAutoScroll;
  74. static char *defFtpLocalDir,*defFtpType;
  75. static Boolean currentFtpPrompt,defFtpPrompt;
  76. static Boolean currentFtpTrace,defFtpTrace;
  77. static Boolean currentFtpStrip,defFtpStrip;
  78. static char *defFtpMailAddress;
  79. static char *defHostWeights;
  80. static Boolean settingsChanged,isPoppedUp;
  81.  
  82. static XtActionsRec actionTable[] = {
  83.     { "popup-settings",        popupSettingsAction },
  84.     { "settings-apply",        applySettingsAction },
  85.     { "settings-default",    defaultSettingsAction },
  86.     { "settings-done",        doneSettingsAction },
  87.     { "set-host",        setHostAction },
  88.     { "set-host-now",        setHostNowAction },
  89.     { "set-search-type",    setSearchTypeAction },
  90.     { "set-search-type-now",    setSearchTypeNowAction },
  91.     { "set-sort-type",        setSortTypeAction },
  92.     { "set-sort-type-now",    setSortTypeNowAction },
  93.     { "set-nice-level",        setNiceLevelAction },
  94.     { "set-nice-level-now",    setNiceLevelNowAction },
  95. };
  96.  
  97. /*    -    -    -    -    -    -    -    -    */
  98. /*
  99.  * initSettings() : Stores away the values of the application resources
  100.  *    at startup for use by the default-settings() action. Also
  101.  *    create the settings panel and register the action procedures.
  102.  */
  103. void
  104. initSettings()
  105. {
  106.     defArchieHost = XtNewString(appResources.archieHost);
  107.     defSearchType = appResources.searchType;
  108.     defSortType = appResources.sortType;
  109.     defNiceLevel = appResources.niceLevel;
  110.     defMaxHits = appResources.maxHits;
  111.     defTimeout = appResources.timeout;
  112.     defRetries = appResources.retries;
  113.     defAutoScroll = appResources.autoScroll;
  114.     defFtpLocalDir = XtNewString(appResources.ftpLocalDir);
  115.     defFtpType = XtNewString(appResources.ftpType);
  116.     defFtpPrompt = appResources.ftpPrompt;
  117.     defFtpTrace = appResources.ftpTrace;
  118.     defFtpStrip = appResources.ftpStrip;
  119.     defFtpMailAddress = XtNewString(appResources.ftpMailAddress);
  120.     defHostWeights = XtNewString(appResources.hostWeights);
  121.     isPoppedUp = False;
  122.     XtAppAddActions(appContext,actionTable,XtNumber(actionTable));
  123.     initSettingsWidgets();
  124. }
  125.  
  126. /*
  127.  * reinitSettings() : Sets the values in the settings editor from the
  128.  *    current state of the application resources.
  129.  */
  130. void
  131. reinitSettings()
  132. {
  133.     char buf[16];
  134.     static int firsttime = 1;
  135.  
  136.     setWidgetString(setHostText,appResources.archieHost);
  137.     updateSettingsSearchType(appResources.searchType);
  138.     updateSettingsSortType(appResources.sortType);
  139.     sprintf(buf,"%d",appResources.niceLevel);
  140.     setWidgetString(setNiceText,buf);
  141.     sprintf(buf,"%d",appResources.maxHits);
  142.     setWidgetString(setMaxHitsText,buf);
  143.     sprintf(buf,"%d",appResources.timeout);
  144.     setWidgetString(setTimeoutText,buf);
  145.     sprintf(buf,"%d",appResources.retries);
  146.     setWidgetString(setRetriesText,buf);
  147.     updateSettingsAutoScroll(appResources.autoScroll);
  148.     /* Kludge to prevent tilde from being expanded in the Text item */
  149.     if (firsttime) {
  150.     setWidgetString(ftpLocalDirText,appResources.ftpLocalDir);
  151.     firsttime = 0;
  152.     }
  153.     updateSettingsFtpType(appResources.ftpType);
  154.     updateSettingsFtpPrompt(appResources.ftpPrompt);
  155.     updateSettingsFtpTrace(appResources.ftpTrace);
  156.     updateSettingsFtpStrip(appResources.ftpStrip);
  157.     setWidgetString(ftpMailAddressText,appResources.ftpMailAddress);
  158.     setWidgetString(setHostWeightsText,appResources.hostWeights);
  159.     setSettingsChangedFlag(False);
  160.     updateSettingsMenuMarks();
  161. }
  162.  
  163. /*
  164.  * initSettingsWidgets() : Create the popup settings editor.
  165.  */
  166. static void
  167. initSettingsWidgets()
  168. {
  169.     Widget form;
  170.  
  171.     settingsShell = XtCreatePopupShell("settingsShell",
  172.                        topLevelShellWidgetClass,toplevel,
  173.                        NULL,0);
  174.     form = XtCreateManagedWidget("settingsForm",formWidgetClass,
  175.                  settingsShell,NULL,0);
  176.     (void) XtCreateManagedWidget("setDoneButton",commandWidgetClass,
  177.                  form,NULL,0);
  178.     setApplyButton = XtCreateManagedWidget("setApplyButton",commandWidgetClass,
  179.                        form,NULL,0);
  180.     (void)XtCreateManagedWidget("setDefaultButton",commandWidgetClass,
  181.                 form,NULL,0);
  182.     (void)XtCreateManagedWidget("setHostButton",menuButtonWidgetClass,
  183.                 form,NULL,0);
  184.     setHostText = XtCreateManagedWidget("setHostText",asciiTextWidgetClass,
  185.                     form,NULL,0);
  186.     (void)XtCreateManagedWidget("setSearchButton",menuButtonWidgetClass,
  187.                 form,NULL,0);
  188.     setSearchLabel = XtCreateManagedWidget("setSearchLabel",labelWidgetClass,
  189.                        form,NULL,0);
  190.     (void)XtCreateManagedWidget("setSortButton",menuButtonWidgetClass,
  191.                 form,NULL,0);
  192.     setSortLabel = XtCreateManagedWidget("setSortLabel",labelWidgetClass,
  193.                      form,NULL,0);
  194.     (void)XtCreateManagedWidget("setNiceButton",menuButtonWidgetClass,
  195.                 form,NULL,0);
  196.     setNiceText = XtCreateManagedWidget("setNiceText",asciiTextWidgetClass,
  197.                     form,NULL,0);
  198.     (void)XtCreateManagedWidget("setMaxHitsLabel",labelWidgetClass,
  199.                 form,NULL,0);
  200.     setMaxHitsText = XtCreateManagedWidget("setMaxHitsText",
  201.                        asciiTextWidgetClass,
  202.                        form,NULL,0);
  203.     (void)XtCreateManagedWidget("setTimeoutLabel",labelWidgetClass,
  204.                 form,NULL,0);
  205.     setTimeoutText = XtCreateManagedWidget("setTimeoutText",
  206.                        asciiTextWidgetClass,
  207.                        form,NULL,0);
  208.     (void)XtCreateManagedWidget("setRetriesLabel",labelWidgetClass,
  209.                 form,NULL,0);
  210.     setRetriesText = XtCreateManagedWidget("setRetriesText",
  211.                        asciiTextWidgetClass,
  212.                        form,NULL,0);
  213.     (void)XtCreateManagedWidget("setAutoScrollButton",menuButtonWidgetClass,
  214.                 form,NULL,0);
  215.     setAutoScrollLabel = XtCreateManagedWidget("setAutoScrollLabel",
  216.                            labelWidgetClass,
  217.                            form,NULL,0);
  218.     (void)XtCreateManagedWidget("ftpMailAddressLabel",labelWidgetClass,
  219.                 form,NULL,0);
  220.     ftpMailAddressText = XtCreateManagedWidget("ftpMailAddressText",
  221.                            asciiTextWidgetClass,
  222.                            form,NULL,0);
  223.     (void)XtCreateManagedWidget("ftpLocalDirLabel",labelWidgetClass,
  224.                 form,NULL,0);
  225.     ftpLocalDirText = XtCreateManagedWidget("ftpLocalDirText",
  226.                         asciiTextWidgetClass,
  227.                         form,NULL,0);
  228.     (void)XtCreateManagedWidget("ftpTypeButton",menuButtonWidgetClass,
  229.                 form,NULL,0);
  230.     ftpTypeLabel = XtCreateManagedWidget("ftpTypeLabel",labelWidgetClass,
  231.                      form,NULL,0);
  232.     (void)XtCreateManagedWidget("ftpPromptButton",menuButtonWidgetClass,
  233.                 form,NULL,0);
  234.     ftpPromptLabel = XtCreateManagedWidget("ftpPromptLabel",labelWidgetClass,
  235.                        form,NULL,0);
  236.     (void)XtCreateManagedWidget("ftpTraceButton",menuButtonWidgetClass,
  237.                 form,NULL,0);
  238.     ftpTraceLabel = XtCreateManagedWidget("ftpTraceLabel",labelWidgetClass,
  239.                        form,NULL,0);
  240.     (void)XtCreateManagedWidget("ftpStripButton",menuButtonWidgetClass,
  241.                 form,NULL,0);
  242.     ftpStripLabel = XtCreateManagedWidget("ftpStripLabel",labelWidgetClass,
  243.                        form,NULL,0);
  244.     setHostWeightsLabel = XtCreateManagedWidget("setHostWeightsLabel",
  245.                         labelWidgetClass,
  246.                         form,NULL,0);
  247.     setHostWeightsText = XtCreateManagedWidget("setHostWeightsText",
  248.                            asciiTextWidgetClass,
  249.                            form,NULL,0);
  250.     /* Add event handler for detecting changes */
  251.     addTextEventHandler(setHostText);
  252.     addTextEventHandler(setMaxHitsText);
  253.     addTextEventHandler(setTimeoutText);
  254.     addTextEventHandler(setRetriesText);
  255.     addTextEventHandler(setNiceText);
  256.     addTextEventHandler(setHostWeightsText);
  257.     addTextEventHandler(ftpMailAddressText);
  258.     addTextEventHandler(ftpLocalDirText);
  259.     XtRealizeWidget(settingsShell);
  260.     /* Enable WM_DELETE_WINDOW handling */
  261.     (void)XSetWMProtocols(XtDisplay(settingsShell),XtWindow(settingsShell),
  262.               &WM_DELETE_WINDOW,1);
  263. }
  264.  
  265. static void
  266. addTextEventHandler(w)
  267. Widget w;
  268. {
  269.     if (w != NULL)
  270.     XtAddEventHandler(w,KeyPressMask|ButtonPressMask,False,
  271.               textEventProc,(XtPointer)NULL);
  272. }
  273.  
  274. void
  275. setSettingsShellState(state)
  276. int state;
  277. {
  278.     if (!isPoppedUp)
  279.     return;
  280.     switch (state) {
  281.     case NormalState:
  282.         XtMapWidget(settingsShell);
  283.         break;
  284.     case IconicState:
  285.         XtUnmapWidget(settingsShell);
  286.         break;
  287.     }
  288. }
  289.  
  290. /*    -    -    -    -    -    -    -    -    */
  291. /* Action procedures */
  292.  
  293. #define ACTION_PROC(NAME)    void NAME(w,event,params,num_params) \
  294.                     Widget w; \
  295.                     XEvent *event; \
  296.                     String *params; \
  297.                     Cardinal *num_params;
  298.  
  299. /*
  300.  * popupSettingsAction() : Pops up the settings editor, and fills it with
  301.  *    the information from the current values of the application settings.
  302.  */
  303. /*ARGSUSED*/
  304. static
  305. ACTION_PROC(popupSettingsAction)
  306. {
  307.     if (isPoppedUp) {
  308.     XRaiseWindow(display,XtWindow(settingsShell));
  309.     } else {
  310.     reinitSettings();
  311.     XtPopup(settingsShell,XtGrabNone);
  312.     isPoppedUp = True;
  313.     }
  314. }
  315.  
  316. /*
  317.  * applySettingsAction() : Callback for apply button - Set the application
  318.  *    resources from the items on the settings editor panel. Some of these
  319.  *    require special action when changed, and this routine does that.
  320.  */
  321. /*ARGSUSED*/
  322. static
  323. ACTION_PROC(applySettingsAction)
  324. {
  325.     char *s;
  326.     int n;
  327.  
  328.     /* Host */
  329.     s = getWidgetString(setHostText);
  330.     if (strcmp(appResources.archieHost,s) != 0) {
  331.     XtFree(appResources.archieHost);
  332.     appResources.archieHost = XtNewString(s);
  333.     setHostMenuMark(appResources.archieHost);
  334.     }
  335.     /* Search type */
  336.     if (appResources.searchType != currentSearchType) {
  337.     appResources.searchType = currentSearchType;
  338.     setSearchMenuMark(appResources.searchType);
  339.     }
  340.     /* Sort type */
  341.     if (appResources.sortType != currentSortType) {
  342.     appResources.sortType = currentSortType;
  343.     setSortMenuMark(appResources.searchType);
  344.     resortBrowser();
  345.     }
  346.     /* Nice level */
  347.     s = getWidgetString(setNiceText);
  348.     n = atoi(s);
  349.     if (n < RDGRAM_MIN_PRI)        /* leave -32766 to -32768 alone */
  350.     n = RDGRAM_MIN_PRI;
  351.     else if (n > RDGRAM_MAX_SPRI)
  352.     n = RDGRAM_MAX_PRI;
  353.     if (appResources.niceLevel != n) {
  354.     appResources.niceLevel = n;
  355.     setNiceMenuMark(appResources.niceLevel);
  356.     }
  357.     /* Max hits */
  358.     s = getWidgetString(setMaxHitsText);
  359.     appResources.maxHits = atoi(s);
  360.     /* Timeout */
  361.     s = getWidgetString(setTimeoutText);
  362.     appResources.timeout = atoi(s);
  363.     /* Retries */
  364.     s = getWidgetString(setRetriesText);
  365.     appResources.retries = atoi(s);
  366.     /* Auto Scroll */
  367.     appResources.autoScroll = currentAutoScroll;
  368.     /* Ftp mail address */
  369.     s = getWidgetString(ftpMailAddressText);
  370.     if (strcmp(appResources.ftpMailAddress,s) != 0) {
  371.     XtFree(appResources.ftpMailAddress);
  372.     appResources.ftpMailAddress = XtNewString(s);
  373.     }
  374.     /* Ftp local dir */
  375.     s = getWidgetString(ftpLocalDirText);
  376.     s = tildeExpand(s);
  377.     if (strcmp(appResources.ftpLocalDir,s) != 0) {
  378.     XtFree(appResources.ftpLocalDir);
  379.     appResources.ftpLocalDir = XtNewString(s);
  380.     }
  381.     /* Ftp type (uses Label not Text) */
  382.     s = getWidgetLabel(ftpTypeLabel);
  383.     if (strcmp(appResources.ftpType,s) != 0) {
  384.     XtFree(appResources.ftpType);
  385.     appResources.ftpType = XtNewString(s);
  386.     }
  387.     /* Ftp prompt */
  388.     appResources.ftpPrompt = currentFtpPrompt;
  389.     /* Ftp trace */
  390.     appResources.ftpTrace = currentFtpTrace;
  391.     /* Ftp strip */
  392.     appResources.ftpStrip = currentFtpStrip;
  393.     /* Host Weights */
  394.     s = getWidgetString(setHostWeightsText);
  395.     if (strcmp(appResources.hostWeights,s) != 0) {
  396.     XtFree(appResources.hostWeights);
  397.     appResources.hostWeights = XtNewString(s);
  398.     reinitHostWeights();
  399.     resortBrowser();
  400.     }
  401.     /* All done */
  402.     setSettingsChangedFlag(False);
  403. }
  404.  
  405. /*
  406.  * defaultSettingsAction() : Callback for default button - Reset the items
  407.  *      to their default values.
  408.  */
  409. /*ARGSUSED*/
  410. static
  411. ACTION_PROC(defaultSettingsAction)
  412. {
  413.     char buf[16];
  414.  
  415.     setWidgetString(setHostText,defArchieHost);
  416.     updateSettingsSearchType(defSearchType);
  417.     updateSettingsSortType(defSortType);
  418.     sprintf(buf,"%d",defNiceLevel);
  419.     setWidgetString(setNiceText,buf);
  420.     sprintf(buf,"%d",defMaxHits);
  421.     setWidgetString(setMaxHitsText,buf);
  422.     sprintf(buf,"%d",defTimeout);
  423.     setWidgetString(setTimeoutText,buf);
  424.     sprintf(buf,"%d",defRetries);
  425.     setWidgetString(setRetriesText,buf);
  426.     updateSettingsAutoScroll(defAutoScroll);
  427.     setWidgetString(ftpMailAddressText,defFtpMailAddress);
  428.     setWidgetString(ftpLocalDirText,defFtpLocalDir);
  429.     updateSettingsFtpType(defFtpType);
  430.     updateSettingsFtpPrompt(defFtpPrompt);
  431.     updateSettingsFtpTrace(defFtpTrace);
  432.     updateSettingsFtpStrip(defFtpStrip);
  433.     setWidgetString(setHostWeightsText,defHostWeights);
  434.     setSettingsChangedFlag(True);
  435. }
  436.  
  437. /*
  438.  * doneSettingsAction() : Callback for done button - Pop down the editor.
  439.  */
  440. /*ARGSUSED*/
  441. static
  442. ACTION_PROC(doneSettingsAction)
  443. {
  444.     if (!settingsChanged || settingsConfirm()) {
  445.     XtPopdown(settingsShell);
  446.     isPoppedUp = False;
  447.     }
  448. }
  449.  
  450. /*    -    -    -    -    -    -    -    -    */
  451. /*
  452.  * setHostAction() : Action procedure to set the host.
  453.  */
  454. /*ARGSUSED*/
  455. static
  456. ACTION_PROC(setHostAction)
  457. {
  458.     if (*num_params != 1) {
  459.     alert0("Incorrect number of arguments to set-host()");
  460.     return;
  461.     }
  462.     if (setHostText == NULL) {
  463.     alert0("set-host() has no effect since setHostText was not created");
  464.     return;
  465.     }
  466.     setWidgetString(setHostText,*params);
  467.     setSettingsChangedFlag(True);
  468. }
  469.  
  470. /*
  471.  * setSearchTypeAction() : Action procedure to set the search type.
  472.  */
  473. /*ARGSUSED*/
  474. static
  475. ACTION_PROC(setSearchTypeAction)
  476. {
  477.     XrmValue from,to;
  478.  
  479.     if (*num_params != 1) {
  480.     alert0("Incorrect number of arguments to set-search-type()");
  481.     return;
  482.     }
  483.     from.addr = *params;
  484.     from.size = sizeof(String);
  485.     to.addr = NULL;
  486.     XtConvertAndStore(w,XtRString,&from,GfRSearchType,&to);
  487.     if (to.addr != NULL)
  488.     updateSettingsSearchType((SearchType)(*(to.addr)));
  489.     setSettingsChangedFlag(True);
  490. }
  491.  
  492. /*
  493.  * setSortTypeAction() : Action procedure to set the sort type.
  494.  */
  495. /*ARGSUSED*/
  496. static
  497. ACTION_PROC(setSortTypeAction)
  498. {
  499.     XrmValue from,to;
  500.  
  501.     if (*num_params != 1) {
  502.     alert0("Incorrect number of arguments to set-sort-type()");
  503.     return;
  504.     }
  505.     from.addr = *params;
  506.     from.size = sizeof(String);
  507.     to.addr = NULL;
  508.     XtConvert(w,XtRString,&from,GfRSortType,&to);
  509.     if (to.addr != NULL)
  510.     updateSettingsSortType((SortType)(*(to.addr)));
  511.     setSettingsChangedFlag(True);
  512. }
  513.  
  514. /*
  515.  * setNiceLevelAction() : Action procedure to set rdgram_priority
  516.  */
  517. /*ARGSUSED*/
  518. static
  519. ACTION_PROC(setNiceLevelAction)
  520. {
  521.     char buf[8];
  522.     int n;
  523.  
  524.     if (*num_params != 1) {
  525.     alert0("Incorrect number of arguments to set-nice-level()");
  526.     return;
  527.     }
  528.     if (setNiceText == NULL) {
  529.        alert0("set-nice-level() has no effect since niceText was not created");
  530.     return;
  531.     }
  532.     n = atoi(*params);
  533.     if (n < RDGRAM_MIN_PRI) {
  534.     alert1("Nice level too negative: %d",(char *)n);
  535.     sprintf(buf,"%d",RDGRAM_MIN_PRI);
  536.     setWidgetString(setNiceText,buf);
  537.     } else if (n > RDGRAM_MAX_PRI) {
  538.     alert1("Nice level too positive: %d",(char *)n);
  539.     sprintf(buf,"%d",RDGRAM_MAX_PRI);
  540.     setWidgetString(setNiceText,buf);
  541.     } else {
  542.     setWidgetString(setNiceText,*params);
  543.     }
  544.     setSettingsChangedFlag(True);
  545. }
  546.  
  547. /*    -    -    -    -    -    -    -    -    */
  548. /* These actions are like their non-Now counterparts, expect that
  549.  * (a) they set appResources immediately rather than waiting for
  550.  *     apply-settings() to be called, and
  551.  * (b) they do not set the changedFlag since they have made the change
  552.  *     globally already.
  553.  * Still, they really aren't meant to be used when the settingsPanel is
  554.  * being displayed.
  555.  */
  556.  
  557. /*ARGSUSED*/
  558. static
  559. ACTION_PROC(setSearchTypeNowAction)
  560. {
  561.     XrmValue from,to;
  562.     SearchType type;
  563.  
  564.     if (*num_params != 1) {
  565.     alert0("Incorrect number of arguments to set-search-type-now()");
  566.     return;
  567.     }
  568.     from.addr = *params;
  569.     from.size = sizeof(String);
  570.     to.addr = NULL;
  571.     XtConvertAndStore(w,XtRString,&from,GfRSearchType,&to);
  572.     if (to.addr != NULL) {
  573.     type = (SearchType)(*(to.addr));
  574.     appResources.searchType = type;
  575.     status1("Set search type to %s",*params);
  576.     updateSettingsSearchType(type);
  577.     }
  578. }
  579.  
  580. /*ARGSUSED*/
  581. static
  582. ACTION_PROC(setSortTypeNowAction)
  583. {
  584.     XrmValue from,to;
  585.     SortType type;
  586.  
  587.     if (*num_params != 1) {
  588.     alert0("Incorrect number of arguments to set-sort-type-now()");
  589.     return;
  590.     }
  591.     from.addr = *params;
  592.     from.size = sizeof(String);
  593.     to.addr = NULL;
  594.     XtConvertAndStore(w,XtRString,&from,GfRSortType,&to);
  595.     if (to.addr != NULL) {
  596.     type = (SortType)(*(to.addr));
  597.     appResources.sortType = type;
  598.     status1("Set sort type to %s",*params);
  599.     updateSettingsSortType(type);
  600.     }
  601. }
  602.  
  603. /*ARGSUSED*/
  604. static
  605. ACTION_PROC(setHostNowAction)
  606. {
  607.     if (*num_params != 1) {
  608.     alert0("Incorrect number of arguments to set-host-now()");
  609.     return;
  610.     }
  611.     XtFree(appResources.archieHost);
  612.     appResources.archieHost = XtNewString(*params);
  613.     status1("Set host to %s",*params);
  614.     setWidgetString(setHostText,*params);
  615. }
  616.  
  617. /*ARGSUSED*/
  618. static
  619. ACTION_PROC(setNiceLevelNowAction)
  620. {
  621.     int n;
  622.  
  623.     if (*num_params != 1) {
  624.     alert0("Incorrect number of arguments to set-nice-level-now()");
  625.     return;
  626.     }
  627.     n = atoi(*params);
  628.     if (n < RDGRAM_MIN_PRI) {
  629.     alert1("Nice level too negative: %d -- not set",(char *)n);
  630.     } else if (n > RDGRAM_MAX_PRI) {
  631.     alert1("Nice level too positive: %d -- not set",(char *)n);
  632.     } else {
  633.     appResources.niceLevel = n;
  634.     status1("Set niceLevel to %d",(char *)n);
  635.     setWidgetString(setNiceText,*params);
  636.     }
  637. }
  638.  
  639. /*    -    -    -    -    -    -    -    -    */
  640. /*
  641.  * textEventProc() : Called whenever the user types in any Text item.
  642.  *      Note that this does NOT detect, eg., selection pastes, as
  643.  *    documented in the BUGS section of the man page.
  644.  */
  645. /*ARGSUSED*/
  646. static void
  647. textEventProc(w,client_data,event,continue_flag)
  648. Widget w;
  649. XtPointer client_data;
  650. XEvent *event;
  651. Boolean *continue_flag;
  652. {
  653.     setSettingsChangedFlag(True);
  654. }
  655.  
  656. /*    -    -    -    -    -    -    -    -    */
  657.  
  658. void
  659. updateSettingsHost(str)
  660. char *str;
  661. {
  662.     setWidgetString(setHostText,str);
  663. }
  664.  
  665. void
  666. updateSettingsSearchType(type)
  667. SearchType type;
  668. {
  669.     currentSearchType = type;
  670.     setWidgetLabel(setSearchLabel,searchTypeToString(type));
  671. }
  672.  
  673. void
  674. updateSettingsSortType(type)
  675. SortType type;
  676. {
  677.     currentSortType = type;
  678.     setWidgetLabel(setSortLabel,sortTypeToString(type));
  679.     if (type == GfWeight) {
  680.     XtMapWidget(setHostWeightsLabel);
  681.     XtMapWidget(setHostWeightsText);
  682.     } else {
  683.     XtUnmapWidget(setHostWeightsLabel);
  684.     XtUnmapWidget(setHostWeightsText);
  685.     }
  686. }
  687.  
  688. void
  689. updateSettingsNiceLevel(level)
  690. int level;
  691. {
  692.     char buf[16];
  693.  
  694.     sprintf(buf,"%d",level);
  695.     setWidgetString(setNiceText,buf);
  696. }
  697.  
  698. void
  699. updateSettingsAutoScroll(flag)
  700. Boolean flag;
  701. {
  702.     currentAutoScroll = flag;
  703.     setWidgetLabel(setAutoScrollLabel,(flag?"yes":"no"));
  704. }
  705.  
  706. void
  707. updateSettingsFtpType(type)
  708. String type;
  709. {
  710.     setWidgetLabel(ftpTypeLabel,type);
  711. }
  712.  
  713. void
  714. updateSettingsFtpPrompt(flag)
  715. Boolean flag;
  716. {
  717.     currentFtpPrompt = flag;
  718.     setWidgetLabel(ftpPromptLabel,(flag?"yes":"no"));
  719. }
  720.  
  721. void
  722. updateSettingsFtpTrace(flag)
  723. Boolean flag;
  724. {
  725.     currentFtpTrace = flag;
  726.     setWidgetLabel(ftpTraceLabel,(flag?"yes":"no"));
  727. }
  728.  
  729. void
  730. updateSettingsFtpStrip(flag)
  731. Boolean flag;
  732. {
  733.     currentFtpStrip = flag;
  734.     setWidgetLabel(ftpStripLabel,(flag?"yes":"no"));
  735. }
  736.  
  737. /*    -    -    -    -    -    -    -    -    */
  738.  
  739. void
  740. setSettingsChangedFlag(value)
  741. Boolean value;
  742. {
  743.     if (setApplyButton != NULL)
  744.     XtSetSensitive(setApplyButton,value);
  745.     settingsChanged = value;
  746. }
  747.  
  748. /*    -    -    -    -    -    -    -    -    */
  749. /* Routines for the popup Dismiss confirmer */
  750.  
  751. static Widget settingsConfirmShell;
  752. static int settingsConfirmResult;
  753.  
  754. static int
  755. settingsConfirm()
  756. {
  757.     if (settingsConfirmShell == NULL)
  758.     settingsConfirmShell =
  759.         createPopup("settingsConfirm",3,settingsConfirmCallback);
  760.     setPopupLabel(settingsConfirmShell,"settingsConfirm",
  761.           "Dismiss without applying changes?");
  762.     popupMainLoop(settingsConfirmShell);
  763.     return(settingsConfirmResult);
  764. }
  765.  
  766. /*ARGSUSED*/
  767. static void
  768. settingsConfirmCallback(w,client_data,call_data)
  769. Widget w;
  770. XtPointer client_data;        /* button number */
  771. XtPointer call_data;
  772. {
  773.     switch ((int)client_data) {
  774.       case 0:            /* Dismiss */
  775.     settingsConfirmResult = 1;
  776.     break;
  777.       case 1:            /* Apply */
  778.     applySettingsAction(w,NULL,NULL,0);
  779.     settingsConfirmResult = 1;
  780.     break;
  781.       case 2:            /* Cancel */
  782.     settingsConfirmResult = 0;
  783.     break;
  784.     }
  785.     popupDone();
  786. }
  787.